package com.way.controller;

import com.way.domain.mall.Order;
import com.way.dto.CommonResult;
import com.way.service.IOrderService;
import com.way.util.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class OrderController {

    @Autowired
    private IOrderService iOrderService;

    @PostMapping("/orders")
    public CommonResult saveOrder(@RequestBody List<Order> orderList) {
        iOrderService.saveOrder(orderList);
        return CommonResult.success();
    }

    @PostMapping("/order")
    public CommonResult saveOrder(@RequestBody Order order) {
        iOrderService.saveOrder(order);
        return CommonResult.success();
    }

    @GetMapping("/order")
    public CommonResult getOrder(Order order) {
        PageUtil.startPage();
        List<Order> orderList = iOrderService.getOrder(order);
        return CommonResult.success(PageUtil.pageResult(orderList));
    }

    @GetMapping("/order/{orderId}")
    public CommonResult getOrder(@PathVariable("orderId") int orderId) {
        return CommonResult.success(iOrderService.getOrder(orderId));
    }
}
